package com.hyc.server.netty.handler;


import com.hyc.Message.testRequest;
import com.hyc.Message.testResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.AllArgsConstructor;

/**
 * @author wxx
 * @version 1.0
 * @create 2024/2/26 16:40
 * 因为是服务器端，我们知道接受到请求格式是RPCRequest
 * Object类型也行，强制转型就行
 */
@AllArgsConstructor
public class NettyRPCServerHandler extends SimpleChannelInboundHandler<testRequest> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, testRequest request) throws Exception {
        //接收request，读取并调用服务
        testResponse response = testResponse.sussess(request);
        ctx.writeAndFlush(response);
        ctx.close();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }


}
